﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HCM_maps_website.Models;

namespace HCM_maps_website.Process.DAL
{
    public class DirectionDAO
    {
        public static string GetStreetName(int id)
        {
            string name = string.Empty;
            string queryStr = string.Format("SELECT fullname FROM street WHERE id={0}", id);
            name = DataProvider.ExecuteString(queryStr);
            return name;
        }

        public static ListNodeInfo GetAllNodeInfo()
        {
            ListNodeInfo resultList = new ListNodeInfo();
            string queryStr = "SELECT * FROM NodeInfo";
            DataTable dt = DataProvider.ExecuteQuery(queryStr);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                NodeInfo_old tempNode = new NodeInfo_old();
                tempNode.Id = Convert.ToInt32(row[0]);
                
               
                tempNode.Location = new Coordinate(Convert.ToDouble(row[1]),Convert.ToDouble(row[2]));
                resultList.addNode(tempNode);
            }

            return resultList;
        }

        public static ListSegmentInfo GetAllSegmentInfo()
        {
            ListSegmentInfo segmentInfoList = new ListSegmentInfo();
            string queryStr = "SELECT * FROM streetsegment";
            DataTable dt = DataProvider.ExecuteQuery(queryStr);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                SegmentInfo segment = new SegmentInfo();
                segment.StartPoint = new NodeInfo_old { Id = Convert.ToInt32(row[0]) };
                segment.EndPoint = new NodeInfo_old { Id = Convert.ToInt32(row[1]) };
                segment.IdStreet = Convert.ToInt32(row[3]);
                segment.Twoway = Convert.ToInt32(row[2]);
                segmentInfoList.addSegmentInfo(segment);
            }
            return segmentInfoList;
        }
    }
}
